package creational.pattern.singleton;

import java.util.UUID;

/**
 * @Author yoyuan
 * @Description: 单例设计模式的实现，通过UUID生成全局唯一ID，
 * @DateTime: 2023/1/8 14:47
 */
public  class IdGenerate {
    public static IdGenerate INSTANCE = null;
    private int TEST_NUM = 0;
    private IdGenerate(){}

    // 因为不能使用构造函数，所以需要将该方法设置为static才能调用
    public static IdGenerate getInstance(){
        if(INSTANCE == null){
            synchronized (IdGenerate.class){
                if (INSTANCE == null)
                    INSTANCE = new IdGenerate();
            }
        }
        return INSTANCE;
    }

    public String getId(){
        return UUID.randomUUID().toString();
    }

    // 用于测试
    public void incr(){
        TEST_NUM ++;
    }
    public int getTEST_NUM(){
        return TEST_NUM;
    }
}
